using HKB.Common;
using HKB.Data.Model;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace HKB.Data.Dal
{
	public class ClientContacter
	{
		public int GetMaxId()
		{
			return Conn.GetMaxID("ContacterID", "HL_ClientContacter");
		}
		public bool Exists(int ContacterID)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select count(1) from HL_ClientContacter");
			stringBuilder.Append(" where ContacterID=@ContacterID");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@ContacterID", SqlDbType.Int, 4)
			};
			array[0].Value = ContacterID;
			return Conn.Exists(stringBuilder.ToString(), array);
		}
		public int Add(HKB.Data.Model.ClientContacter model)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("insert into HL_ClientContacter(");
			stringBuilder.Append("ClientID,UserName,UserType,TrueName,Sex,Title,Company,Department,Position,Operation,CompanyAddress,Email,Homepage,QQ,MSN,Yahoo,UC,OfficePhone,HomePhone,Fax,Mobile,Country,Province,City,Address,ZipCode,NativePlace,Nation,Birthday,IDCard,Marriage,Family,Income,Education,GraduateFrom,InterestsOfLife,InterestsOfCulture,InterestsOfAmusement,InterestsOfSport,InterestsOfOther,CreateTime,UpdateTime,Owner,Districts)");
			stringBuilder.Append(" values (");
			stringBuilder.Append("@ClientID,@UserName,@UserType,@TrueName,@Sex,@Title,@Company,@Department,@Position,@Operation,@CompanyAddress,@Email,@Homepage,@QQ,@MSN,@Yahoo,@UC,@OfficePhone,@HomePhone,@Fax,@Mobile,@Country,@Province,@City,@Address,@ZipCode,@NativePlace,@Nation,@Birthday,@IDCard,@Marriage,@Family,@Income,@Education,@GraduateFrom,@InterestsOfLife,@InterestsOfCulture,@InterestsOfAmusement,@InterestsOfSport,@InterestsOfOther,@CreateTime,@UpdateTime,@Owner,@Districts)");
			stringBuilder.Append(";select @@IDENTITY");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@ClientID", SqlDbType.Int, 4),
				new SqlParameter("@UserName", SqlDbType.NVarChar, 100),
				new SqlParameter("@UserType", SqlDbType.NVarChar, 30),
				new SqlParameter("@TrueName", SqlDbType.NVarChar, 20),
				new SqlParameter("@Sex", SqlDbType.Int, 4),
				new SqlParameter("@Title", SqlDbType.NVarChar, 50),
				new SqlParameter("@Company", SqlDbType.NVarChar, 100),
				new SqlParameter("@Department", SqlDbType.NVarChar, 50),
				new SqlParameter("@Position", SqlDbType.NVarChar, 50),
				new SqlParameter("@Operation", SqlDbType.NVarChar, 50),
				new SqlParameter("@CompanyAddress", SqlDbType.NVarChar, 200),
				new SqlParameter("@Email", SqlDbType.NVarChar, 100),
				new SqlParameter("@Homepage", SqlDbType.NVarChar, 255),
				new SqlParameter("@QQ", SqlDbType.NVarChar, 20),
				new SqlParameter("@MSN", SqlDbType.NVarChar, 100),
				new SqlParameter("@Yahoo", SqlDbType.NVarChar, 100),
				new SqlParameter("@UC", SqlDbType.NVarChar, 100),
				new SqlParameter("@OfficePhone", SqlDbType.NVarChar, 30),
				new SqlParameter("@HomePhone", SqlDbType.NVarChar, 30),
				new SqlParameter("@Fax", SqlDbType.NVarChar, 30),
				new SqlParameter("@Mobile", SqlDbType.NVarChar, 30),
				new SqlParameter("@Country", SqlDbType.NVarChar, 50),
				new SqlParameter("@Province", SqlDbType.NVarChar, 30),
				new SqlParameter("@City", SqlDbType.NVarChar, 30),
				new SqlParameter("@Address", SqlDbType.NVarChar, 255),
				new SqlParameter("@ZipCode", SqlDbType.NVarChar, 10),
				new SqlParameter("@NativePlace", SqlDbType.NVarChar, 50),
				new SqlParameter("@Nation", SqlDbType.NVarChar, 50),
				new SqlParameter("@Birthday", SqlDbType.DateTime),
				new SqlParameter("@IDCard", SqlDbType.NVarChar, 20),
				new SqlParameter("@Marriage", SqlDbType.Int, 4),
				new SqlParameter("@Family", SqlDbType.NText),
				new SqlParameter("@Income", SqlDbType.NVarChar, 30),
				new SqlParameter("@Education", SqlDbType.NVarChar, 30),
				new SqlParameter("@GraduateFrom", SqlDbType.NVarChar, 255),
				new SqlParameter("@InterestsOfLife", SqlDbType.NVarChar, 255),
				new SqlParameter("@InterestsOfCulture", SqlDbType.NVarChar, 255),
				new SqlParameter("@InterestsOfAmusement", SqlDbType.NVarChar, 255),
				new SqlParameter("@InterestsOfSport", SqlDbType.NVarChar, 255),
				new SqlParameter("@InterestsOfOther", SqlDbType.NVarChar, 255),
				new SqlParameter("@CreateTime", SqlDbType.DateTime),
				new SqlParameter("@UpdateTime", SqlDbType.DateTime),
				new SqlParameter("@Owner", SqlDbType.Int, 4),
				new SqlParameter("@Districts", SqlDbType.NVarChar, 100)
			};
			array[0].Value = model.ClientID;
			array[1].Value = model.UserName;
			array[2].Value = model.UserType;
			array[3].Value = model.TrueName;
			array[4].Value = model.Sex;
			array[5].Value = model.Title;
			array[6].Value = model.Company;
			array[7].Value = model.Department;
			array[8].Value = model.Position;
			array[9].Value = model.Operation;
			array[10].Value = model.CompanyAddress;
			array[11].Value = model.Email;
			array[12].Value = model.Homepage;
			array[13].Value = model.QQ;
			array[14].Value = model.MSN;
			array[15].Value = model.Yahoo;
			array[16].Value = model.UC;
			array[17].Value = model.OfficePhone;
			array[18].Value = model.HomePhone;
			array[19].Value = model.Fax;
			array[20].Value = model.Mobile;
			array[21].Value = model.Country;
			array[22].Value = model.Province;
			array[23].Value = model.City;
			array[24].Value = model.Address;
			array[25].Value = model.ZipCode;
			array[26].Value = model.NativePlace;
			array[27].Value = model.Nation;
			array[28].Value = model.Birthday;
			array[29].Value = model.IDCard;
			array[30].Value = model.Marriage;
			array[31].Value = model.Family;
			array[32].Value = model.Income;
			array[33].Value = model.Education;
			array[34].Value = model.GraduateFrom;
			array[35].Value = model.InterestsOfLife;
			array[36].Value = model.InterestsOfCulture;
			array[37].Value = model.InterestsOfAmusement;
			array[38].Value = model.InterestsOfSport;
			array[39].Value = model.InterestsOfOther;
			array[40].Value = model.CreateTime;
			array[41].Value = model.UpdateTime;
			array[42].Value = model.Owner;
			array[43].Value = model.Districts;
			object single = Conn.GetSingle(stringBuilder.ToString(), array);
			int result;
			if (single == null)
			{
				result = 0;
			}
			else
			{
				result = System.Convert.ToInt32(single);
			}
			return result;
		}
		public bool Update(HKB.Data.Model.ClientContacter model)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("update HL_ClientContacter set ");
			stringBuilder.Append("ClientID=" + model.ClientID);
			bool result;
			try
			{
				if (!string.IsNullOrEmpty(model.UserType))
				{
					stringBuilder.Append(",UserType='" + model.UserType + "'");
				}
				if (!string.IsNullOrEmpty(model.TrueName))
				{
					stringBuilder.Append(",TrueName='" + model.TrueName + "'");
				}
				if (!string.IsNullOrEmpty(model.Sex.ToString()))
				{
					stringBuilder.Append(",Sex='" + model.Sex + "'");
				}
				if (!string.IsNullOrEmpty(model.Title))
				{
					stringBuilder.Append(",Title='" + model.Title + "'");
				}
				if (!string.IsNullOrEmpty(model.Company))
				{
					stringBuilder.Append(",Company='" + model.Company + "'");
				}
				if (!string.IsNullOrEmpty(model.Department))
				{
					stringBuilder.Append(",Department='" + model.Department + "'");
				}
				if (!string.IsNullOrEmpty(model.Position))
				{
					stringBuilder.Append(",Position='" + model.Position + "'");
				}
				if (!string.IsNullOrEmpty(model.Operation))
				{
					stringBuilder.Append(",Operation='" + model.Operation + "'");
				}
				if (!string.IsNullOrEmpty(model.CompanyAddress))
				{
					stringBuilder.Append(",CompanyAddress='" + model.CompanyAddress + "'");
				}
				if (!string.IsNullOrEmpty(model.Email))
				{
					stringBuilder.Append(",Email='" + model.Email + "'");
				}
				if (!string.IsNullOrEmpty(model.Homepage))
				{
					stringBuilder.Append(",Homepage='" + model.Homepage + "'");
				}
				if (!string.IsNullOrEmpty(model.QQ))
				{
					stringBuilder.Append(",QQ='" + model.QQ + "'");
				}
				if (!string.IsNullOrEmpty(model.MSN))
				{
					stringBuilder.Append(",MSN='" + model.MSN + "'");
				}
				if (!string.IsNullOrEmpty(model.Yahoo))
				{
					stringBuilder.Append(",Yahoo='" + model.Yahoo + "'");
				}
				if (!string.IsNullOrEmpty(model.UC))
				{
					stringBuilder.Append(",UC='" + model.UC + "'");
				}
				if (!string.IsNullOrEmpty(model.OfficePhone))
				{
					stringBuilder.Append(",OfficePhone='" + model.OfficePhone + "'");
				}
				if (!string.IsNullOrEmpty(model.HomePhone))
				{
					stringBuilder.Append(",HomePhone='" + model.HomePhone + "'");
				}
				if (!string.IsNullOrEmpty(model.Fax))
				{
					stringBuilder.Append(",Fax='" + model.Fax + "'");
				}
				if (!string.IsNullOrEmpty(model.Mobile))
				{
					stringBuilder.Append(",Mobile='" + model.Mobile + "'");
				}
				if (!string.IsNullOrEmpty(model.Country))
				{
					stringBuilder.Append(",Country='" + model.Country + "'");
				}
				if (!string.IsNullOrEmpty(model.Province))
				{
					stringBuilder.Append(",Province='" + model.Province + "'");
				}
				if (!string.IsNullOrEmpty(model.City))
				{
					stringBuilder.Append(",City='" + model.City + "'");
				}
				if (!string.IsNullOrEmpty(model.Districts))
				{
					stringBuilder.Append(",Districts='" + model.Districts + "'");
				}
				if (!string.IsNullOrEmpty(model.Address))
				{
					stringBuilder.Append(",Address='" + model.Address + "'");
				}
				if (!string.IsNullOrEmpty(model.ZipCode))
				{
					stringBuilder.Append(",ZipCode='" + model.ZipCode + "'");
				}
				if (!string.IsNullOrEmpty(model.NativePlace))
				{
					stringBuilder.Append(",NativePlace='" + model.NativePlace + "'");
				}
				if (!string.IsNullOrEmpty(model.Nation))
				{
					stringBuilder.Append(",Nation='" + model.Nation + "'");
				}
				if (model.Birthday.HasValue)
				{
					stringBuilder.Append(",Birthday='" + model.Birthday + "'");
				}
				if (!string.IsNullOrEmpty(model.IDCard))
				{
					stringBuilder.Append(",IDCard='" + model.IDCard + "'");
				}
				if (!string.IsNullOrEmpty(model.Marriage.ToString()))
				{
					stringBuilder.Append(",Marriage='" + model.Marriage + "'");
				}
				if (!string.IsNullOrEmpty(model.Family))
				{
					stringBuilder.Append(",Family='" + model.Family + "'");
				}
				if (!string.IsNullOrEmpty(model.Income))
				{
					stringBuilder.Append(",Income='" + model.Income + "'");
				}
				if (!string.IsNullOrEmpty(model.Education))
				{
					stringBuilder.Append(",Education='" + model.Education + "'");
				}
				if (!string.IsNullOrEmpty(model.GraduateFrom))
				{
					stringBuilder.Append(",GraduateFrom='" + model.GraduateFrom + "'");
				}
				if (!string.IsNullOrEmpty(model.InterestsOfLife))
				{
					stringBuilder.Append(",InterestsOfLife='" + model.InterestsOfLife + "'");
				}
				if (!string.IsNullOrEmpty(model.InterestsOfCulture))
				{
					stringBuilder.Append(",InterestsOfCulture='" + model.InterestsOfCulture + "'");
				}
				if (!string.IsNullOrEmpty(model.InterestsOfAmusement))
				{
					stringBuilder.Append(",InterestsOfAmusement='" + model.InterestsOfAmusement + "'");
				}
				if (!string.IsNullOrEmpty(model.InterestsOfSport))
				{
					stringBuilder.Append(",InterestsOfSport='" + model.InterestsOfSport + "'");
				}
				if (!string.IsNullOrEmpty(model.InterestsOfOther))
				{
					stringBuilder.Append(",InterestsOfOther='" + model.InterestsOfOther + "'");
				}
				if (model.UpdateTime.HasValue)
				{
					stringBuilder.Append(",UpdateTime='" + model.UpdateTime + "'");
				}
				if (!string.IsNullOrEmpty(model.Owner.ToString()))
				{
					stringBuilder.Append(",Owner=" + model.Owner);
				}
				if (!string.IsNullOrEmpty(model.UserName))
				{
					stringBuilder.Append(",UserName='" + model.UserName + "'");
				}
				stringBuilder.Append(" where ContacterID=@ContacterID");
				SqlParameter[] array = new SqlParameter[]
				{
					new SqlParameter("@ContacterID", SqlDbType.Int, 4)
				};
				array[0].Value = model.ContacterID;
				int num = Conn.ExecuteSql(stringBuilder.ToString(), array);
				if (num > 0)
				{
					result = true;
				}
				else
				{
					result = false;
				}
			}
			catch (System.Exception ex)
			{
				throw ex;
			}
			return result;
		}
		public bool Delete(int ContacterID)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("delete from HL_ClientContacter ");
			stringBuilder.Append(" where ContacterID=@ContacterID");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@ContacterID", SqlDbType.Int, 4)
			};
			array[0].Value = ContacterID;
			int num = Conn.ExecuteSql(stringBuilder.ToString(), array);
			return num > 0;
		}
		public bool DeleteList(string ContacterIDlist)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("delete from HL_ClientContacter ");
			stringBuilder.Append(" where ContacterID in (" + ContacterIDlist + ")  ");
			int num = Conn.ExecuteSql(stringBuilder.ToString(), new IDbDataParameter[0]);
			return num > 0;
		}
		public HKB.Data.Model.ClientContacter GetModel(int ContacterID)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select  top 1 *  from HL_ClientContacter ");
			stringBuilder.Append(" where ContacterID=@ContacterID");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@ContacterID", SqlDbType.Int, 4)
			};
			array[0].Value = ContacterID;
			HKB.Data.Model.ClientContacter clientContacter = new HKB.Data.Model.ClientContacter();
			DataSet dataSet = Conn.Query(stringBuilder.ToString(), array);
			HKB.Data.Model.ClientContacter result;
			if (dataSet.Tables[0].Rows.Count > 0)
			{
				result = this.DataRowToModel(dataSet.Tables[0].Rows[0]);
			}
			else
			{
				result = null;
			}
			return result;
		}
		public HKB.Data.Model.ClientContacter DataRowToModel(DataRow row)
		{
			HKB.Data.Model.ClientContacter clientContacter = new HKB.Data.Model.ClientContacter();
			if (row != null)
			{
				if (row["ContacterID"] != null && row["ContacterID"].ToString() != "")
				{
					clientContacter.ContacterID = int.Parse(row["ContacterID"].ToString());
				}
				if (row["ClientID"] != null && row["ClientID"].ToString() != "")
				{
					clientContacter.ClientID = new int?(int.Parse(row["ClientID"].ToString()));
				}
				if (row["UserName"] != null)
				{
					clientContacter.UserName = row["UserName"].ToString();
				}
				if (row["UserType"] != null)
				{
					clientContacter.UserType = row["UserType"].ToString();
				}
				if (row["TrueName"] != null)
				{
					clientContacter.TrueName = row["TrueName"].ToString();
				}
				if (row["Sex"] != System.DBNull.Value)
				{
					clientContacter.Sex = System.Convert.ToInt32(row["Sex"].ToString());
				}
				if (row["Title"] != null)
				{
					clientContacter.Title = row["Title"].ToString();
				}
				if (row["Company"] != null)
				{
					clientContacter.Company = row["Company"].ToString();
				}
				if (row["Department"] != null)
				{
					clientContacter.Department = row["Department"].ToString();
				}
				if (row["Position"] != null)
				{
					clientContacter.Position = row["Position"].ToString();
				}
				if (row["Operation"] != null)
				{
					clientContacter.Operation = row["Operation"].ToString();
				}
				if (row["CompanyAddress"] != null)
				{
					clientContacter.CompanyAddress = row["CompanyAddress"].ToString();
				}
				if (row["Email"] != null)
				{
					clientContacter.Email = row["Email"].ToString();
				}
				if (row["Homepage"] != null)
				{
					clientContacter.Homepage = row["Homepage"].ToString();
				}
				if (row["QQ"] != null)
				{
					clientContacter.QQ = row["QQ"].ToString();
				}
				if (row["MSN"] != null)
				{
					clientContacter.MSN = row["MSN"].ToString();
				}
				if (row["Yahoo"] != null)
				{
					clientContacter.Yahoo = row["Yahoo"].ToString();
				}
				if (row["UC"] != null)
				{
					clientContacter.UC = row["UC"].ToString();
				}
				if (row["OfficePhone"] != null)
				{
					clientContacter.OfficePhone = row["OfficePhone"].ToString();
				}
				if (row["HomePhone"] != null)
				{
					clientContacter.HomePhone = row["HomePhone"].ToString();
				}
				if (row["Fax"] != null)
				{
					clientContacter.Fax = row["Fax"].ToString();
				}
				if (row["Mobile"] != null)
				{
					clientContacter.Mobile = row["Mobile"].ToString();
				}
				if (row["Country"] != null)
				{
					clientContacter.Country = row["Country"].ToString();
				}
				if (row["Province"] != null)
				{
					clientContacter.Province = row["Province"].ToString();
				}
				if (row["City"] != null)
				{
					clientContacter.City = row["City"].ToString();
				}
				if (row["Districts"] != System.DBNull.Value)
				{
					clientContacter.Districts = row["Districts"].ToString();
				}
				if (row["Address"] != null)
				{
					clientContacter.Address = row["Address"].ToString();
				}
				if (row["ZipCode"] != null)
				{
					clientContacter.ZipCode = row["ZipCode"].ToString();
				}
				if (row["NativePlace"] != null)
				{
					clientContacter.NativePlace = row["NativePlace"].ToString();
				}
				if (row["Nation"] != null)
				{
					clientContacter.Nation = row["Nation"].ToString();
				}
				if (row["Birthday"] != null && row["Birthday"].ToString() != "")
				{
					clientContacter.Birthday = new System.DateTime?(System.DateTime.Parse(row["Birthday"].ToString()));
				}
				if (row["IDCard"] != null)
				{
					clientContacter.IDCard = row["IDCard"].ToString();
				}
				if (row["Marriage"] != System.DBNull.Value)
				{
					clientContacter.Marriage = System.Convert.ToInt32(row["Marriage"].ToString());
				}
				if (row["Family"] != null)
				{
					clientContacter.Family = row["Family"].ToString();
				}
				if (row["Income"] != null)
				{
					clientContacter.Income = row["Income"].ToString();
				}
				if (row["Education"] != null)
				{
					clientContacter.Education = row["Education"].ToString();
				}
				if (row["GraduateFrom"] != null)
				{
					clientContacter.GraduateFrom = row["GraduateFrom"].ToString();
				}
				if (row["InterestsOfLife"] != null)
				{
					clientContacter.InterestsOfLife = row["InterestsOfLife"].ToString();
				}
				if (row["InterestsOfCulture"] != null)
				{
					clientContacter.InterestsOfCulture = row["InterestsOfCulture"].ToString();
				}
				if (row["InterestsOfAmusement"] != null)
				{
					clientContacter.InterestsOfAmusement = row["InterestsOfAmusement"].ToString();
				}
				if (row["InterestsOfSport"] != null)
				{
					clientContacter.InterestsOfSport = row["InterestsOfSport"].ToString();
				}
				if (row["InterestsOfOther"] != null)
				{
					clientContacter.InterestsOfOther = row["InterestsOfOther"].ToString();
				}
				if (row["CreateTime"] != null && row["CreateTime"].ToString() != "")
				{
					clientContacter.CreateTime = new System.DateTime?(System.DateTime.Parse(row["CreateTime"].ToString()));
				}
				if (row["UpdateTime"] != null && row["UpdateTime"].ToString() != "")
				{
					clientContacter.UpdateTime = new System.DateTime?(System.DateTime.Parse(row["UpdateTime"].ToString()));
				}
				if (row["Owner"] != null && row["Owner"].ToString() != "")
				{
					clientContacter.Owner = int.Parse(row["Owner"].ToString());
				}
			}
			return clientContacter;
		}
		public DataSet GetList(string strWhere)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select * ");
			stringBuilder.Append(" FROM HL_ClientContacter ");
			if (strWhere.Trim() != "")
			{
				stringBuilder.Append(" where " + strWhere);
			}
			return Conn.Query(stringBuilder.ToString(), new IDbDataParameter[0]);
		}
		public DataSet GetList(int Top, string strWhere, string filedOrder)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select ");
			if (Top > 0)
			{
				stringBuilder.Append(" top " + Top.ToString());
			}
			stringBuilder.Append(" * FROM HL_ClientContacter ");
			if (strWhere.Trim() != "")
			{
				stringBuilder.Append(" where " + strWhere);
			}
			stringBuilder.Append(" order by " + filedOrder);
			return Conn.Query(stringBuilder.ToString(), new IDbDataParameter[0]);
		}
		public int GetRecordCount(string strWhere)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select count(1) FROM HL_ClientContacter ");
			if (strWhere.Trim() != "")
			{
				stringBuilder.Append(" where " + strWhere);
			}
			object single = DbHelperSQL.GetSingle(stringBuilder.ToString());
			int result;
			if (single == null)
			{
				result = 0;
			}
			else
			{
				result = System.Convert.ToInt32(single);
			}
			return result;
		}
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("SELECT * FROM ( ");
			stringBuilder.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				stringBuilder.Append("order by T." + orderby);
			}
			else
			{
				stringBuilder.Append("order by T.ContacterID desc");
			}
			stringBuilder.Append(")AS Row, T.*  from HL_ClientContacter T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				stringBuilder.Append(" WHERE " + strWhere);
			}
			stringBuilder.Append(" ) TT");
			stringBuilder.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return Conn.Query(stringBuilder.ToString(), new IDbDataParameter[0]);
		}
		public HKB.Data.Model.ClientContacter GetContacterByClientId(int clientId, int owner)
		{
			string text = string.Concat(new object[]
			{
				"select cc.* from HL_Client as c,HL_ClientContacter as cc where c.ClientID=cc.ClientID and ClientType='ClientType_gr' and cc.ClientID=",
				clientId,
				" and cc.Owner=",
				owner
			});
			DataSet dataSet = Conn.Query(text.ToString(), new IDbDataParameter[0]);
			HKB.Data.Model.ClientContacter result;
			if (dataSet.Tables[0].Rows.Count > 0)
			{
				result = this.DataRowToModel(dataSet.Tables[0].Rows[0]);
			}
			else
			{
				result = null;
			}
			return result;
		}
		public DataSet GetContacterListByClientId(int clientId)
		{
			string text = "select * from HL_ClientContacter where ClientID=" + clientId;
			return Conn.Query(text.ToString(), new IDbDataParameter[0]);
		}
		public HKB.Data.Model.ClientContacter GetContacterByTrueName(string trueName)
		{
			string text = "select * from HL_ClientContacter where TrueName='" + trueName + "'";
			DataSet dataSet = Conn.Query(text.ToString(), new IDbDataParameter[0]);
			HKB.Data.Model.ClientContacter result;
			if (dataSet.Tables[0].Rows.Count > 0)
			{
				result = this.DataRowToModel(dataSet.Tables[0].Rows[0]);
			}
			else
			{
				result = null;
			}
			return result;
		}
		public int GetListCount(string strSQL)
		{
			object single = DbHelperSQL.GetSingle(strSQL.ToString());
			int result;
			if (single == null)
			{
				result = 0;
			}
			else
			{
				result = System.Convert.ToInt32(single);
			}
			return result;
		}
		public DataSet GetContacterListByPage(string strSQL, string row, int startIndex, int endIndex)
		{
			string text = string.Concat(new object[]
			{
				"SELECT * FROM ( ",
				strSQL,
				" ) as TT WHERE TT.",
				row,
				" between ",
				startIndex,
				" and ",
				endIndex
			});
			return Conn.Query(text.ToString(), new IDbDataParameter[0]);
		}
		public DataSet GetShortList(string strWhere)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select ContacterID,TrueName,Email,QQ,OfficePhone,Mobile");
			stringBuilder.Append(" FROM HL_ClientContacter ");
			if (strWhere.Trim() != "")
			{
				stringBuilder.Append(" where " + strWhere);
			}
			return Conn.Query(stringBuilder.ToString(), new IDbDataParameter[0]);
		}
		public int AddShort(HKB.Data.Model.ClientContacter model)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("insert into HL_ClientContacter(");
			stringBuilder.Append("ClientID,TrueName,Email,QQ,OfficePhone,Mobile,CreateTime,UpdateTime,Owner)");
			stringBuilder.Append(" values (");
			stringBuilder.Append("@ClientID,@TrueName,@Email,@QQ,@OfficePhone,@Mobile,@CreateTime,@UpdateTime,@Owner)");
			stringBuilder.Append(";select @@IDENTITY");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@ClientID", SqlDbType.Int, 4),
				new SqlParameter("@TrueName", SqlDbType.NVarChar, 20),
				new SqlParameter("@Email", SqlDbType.NVarChar, 100),
				new SqlParameter("@QQ", SqlDbType.NVarChar, 20),
				new SqlParameter("@OfficePhone", SqlDbType.NVarChar, 30),
				new SqlParameter("@Mobile", SqlDbType.NVarChar, 30),
				new SqlParameter("@CreateTime", SqlDbType.DateTime),
				new SqlParameter("@UpdateTime", SqlDbType.DateTime),
				new SqlParameter("@Owner", SqlDbType.Int, 4)
			};
			array[0].Value = model.ClientID;
			array[1].Value = model.TrueName;
			array[2].Value = model.Email;
			array[3].Value = model.QQ;
			array[4].Value = model.OfficePhone;
			array[5].Value = model.Mobile;
			array[6].Value = System.DateTime.Now;
			array[7].Value = System.DateTime.Now;
			array[8].Value = model.Owner;
			object single = Conn.GetSingle(stringBuilder.ToString(), array);
			int result;
			if (single == null)
			{
				result = 0;
			}
			else
			{
				result = System.Convert.ToInt32(single);
			}
			return result;
		}
		public bool UpdateShort(HKB.Data.Model.ClientContacter model)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("update HL_ClientContacter set ");
			stringBuilder.Append("ClientID=@ClientID,");
			stringBuilder.Append("TrueName=@TrueName,");
			stringBuilder.Append("Email=@Email,");
			stringBuilder.Append("QQ=@QQ,");
			stringBuilder.Append("OfficePhone=@OfficePhone,");
			stringBuilder.Append("Mobile=@Mobile,");
			stringBuilder.Append("UpdateTime=@UpdateTime,");
			stringBuilder.Append("Owner=@Owner");
			stringBuilder.Append(" where ContacterID=@ContacterID");
			SqlParameter[] array = new SqlParameter[]
			{
				new SqlParameter("@ClientID", SqlDbType.Int, 4),
				new SqlParameter("@TrueName", SqlDbType.NVarChar, 20),
				new SqlParameter("@Email", SqlDbType.NVarChar, 100),
				new SqlParameter("@QQ", SqlDbType.NVarChar, 20),
				new SqlParameter("@OfficePhone", SqlDbType.NVarChar, 30),
				new SqlParameter("@Mobile", SqlDbType.NVarChar, 30),
				new SqlParameter("@UpdateTime", SqlDbType.DateTime),
				new SqlParameter("@Owner", SqlDbType.Int, 4),
				new SqlParameter("@ContacterID", SqlDbType.Int, 4)
			};
			array[0].Value = model.ClientID;
			array[1].Value = model.TrueName;
			array[2].Value = model.Email;
			array[3].Value = model.QQ;
			array[4].Value = model.OfficePhone;
			array[5].Value = model.Mobile;
			array[6].Value = model.UpdateTime;
			array[7].Value = model.Owner;
			array[8].Value = model.ContacterID;
			int num = Conn.ExecuteSql(stringBuilder.ToString(), array);
			return num > 0;
		}
	}
}
